package com.ruoyi.loan.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.loan.domain.TbRate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.loan.service.ITbRateService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 利率Controller
 * 
 * @author jy
 * @date 2023-01-14
 */
@RestController
@RequestMapping("/rate")
public class TbRateController extends BaseController
{
    @Autowired
    private ITbRateService tbRateService;

    /**
     * 查询利率列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbRate tbRate)
    {
        startPage();
        List<TbRate> list = tbRateService.selectTbRateList(tbRate);
        return getDataTable(list);
    }

    /**
     * 导出利率列表
     */
    @Log(title = "利率", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbRate tbRate)
    {
        List<TbRate> list = tbRateService.selectTbRateList(tbRate);
        ExcelUtil<TbRate> util = new ExcelUtil<TbRate>(TbRate.class);
        util.exportExcel(response, list, "利率数据");
    }

    /**
     * 获取利率详细信息
     */
    @GetMapping(value = "/getRate/{rateId}")
    public AjaxResult getInfo(@PathVariable("rateId") Long rateId)
    {
        return success(tbRateService.selectTbRateByRateId(rateId));
    }

    /**
     * 新增利率
     */
    @Log(title = "利率", businessType = BusinessType.INSERT)
    @PostMapping("/addRate")
    public AjaxResult add(@RequestBody TbRate tbRate)
    {
        return toAjax(tbRateService.insertTbRate(tbRate));
    }

    /**
     * 修改利率
     */
    @Log(title = "利率", businessType = BusinessType.UPDATE)
    @PutMapping("/updateRate")
    public AjaxResult edit(@RequestBody TbRate tbRate)
    {
        return toAjax(tbRateService.updateTbRate(tbRate));
    }

    /**
     * 删除利率
     */
    @RequiresPermissions("system:rate:remove")
    @Log(title = "利率", businessType = BusinessType.DELETE)
	@DeleteMapping("/delRate/{rateIds}")
    public AjaxResult remove(@PathVariable Long[] rateIds)
    {
        return toAjax(tbRateService.deleteTbRateByRateIds(rateIds));
    }
}
